var ctx, headUrl;

function setResourceCtx(ctx) {
	this.ctx = ctx;
	this.headUrl = ctx +"/member/";
}

function exit() {
	deleteCookie('loginName');
	deleteCookie('password');
	logout();
}

//验证用户名/手机号
function Identify(identification) { 
	$.ajax({
        type : "GET",
        async : false,
        url : headUrl + "Identify",
        cache : false,
        dataType : 'json',
        data:{
        	identification : identification
        },
        success : function(result) {
        	IdentifyResult(result);
        }
	});
}
	
//获取短信验证码
function getVerification(phone,codeType) {
	$.ajax({
        type : "GET",
        url : headUrl + "generalVerification",
        cache : false,
        dataType : 'json',
        data:{
        	phone : phone,
			codeType: codeType
        },
        success : function(result) {
        	getVerificationResult(result);
        }
	});
}

//验证码短信验证码、图形验证码
function JudgeVerification(phone, verification, codePhone) {
	$.ajax({
        type : "GET",
        url : headUrl + "JudgeVerification",
        cache : false,
        dataType : 'json',
        data:{
        	phone : phone,
			verification : verification,
			codePhone : codePhone
        },
        success : function(result) {
        	JudgeVerificationResult(result);
        }
	});
}
//验证码邮箱证码
function JudgeVerifications(phone, verification, codePhone) {
	$.ajax({
		type : "GET",
		url : headUrl + "JudgeVerification",
		cache : false,
		dataType : 'json',
		data:{
			phone : phone,
			verification : verification,
			codePhone : codePhone
		},
		success : function(result) {
			JudgeVerificationResults(result);
		}
	});
}

//修改密码
function modifyPsw(loginName, newPsw, pwdGrade, codePwd) {
	$.ajax({
        type : "GET",
        url : headUrl + "modifyPsw",
        cache : false,
        dataType : 'json',
        data:{
        	loginName : loginName,
			newPsw : newPsw,
			pwdGrade : pwdGrade,
			codePwd :codePwd
        },
        success : function(result) {
        	modifyPswResult(result);
        }
	});
}

//注册
function registMember(loginName, pwd, pwdGrade, phone,email, code) {
	$.ajax({
        type : "POST",
        url : headUrl + "registMember",
        cache : false,
        dataType : 'json',
        data:{
        	loginName : loginName,
			pwd : pwd,
			pwdGrade : pwdGrade,
			phone : phone,
			email : email,
			code : code
        },
        success : function(result) {
        	registMemberResult(result);
        }
	});
}

//登录
function login(loginName, pwd, isSel) {
	$.ajax({
        type : "GET",
        url : headUrl + "login",
        cache : false,
        dataType : 'json',
        data:{
        	loginname : loginName,
			pwd : pwd,
			isSel : isSel
        },
        success : function(result) {
        	loginResult(result);
        }
	});
}

//退出
function logout() {
	headUrl = ctx +"/member/";
	$.ajax({
        type : "GET",
        url : headUrl + "logout",
        success : function(result) {
        	if (result.success) {
        		window.location.href = ctx + '/';
        	}
        }
	});
}

//修改会员信息
function updateMemberInfo(sex, birthday, email, memberName, address) {
	$.ajax({
        type : "POST",
        url : headUrl + "updateMemberInfo",
        cache : false,
        dataType : 'json',
        data:{
        	sex : sex,
        	birthday : birthday,
        	email : email,
        	memberName : memberName,
        	address : address
        },
        success : function(result) {
        	updateMemberInfoResult(result);
        }
	});
}

function updateMemberPhone(phone){
	$.ajax({
        type : "POST",
        url : headUrl + "updateMemberPhone",
        cache : false,
        dataType : 'json',
        data:{
        	phone : phone
        },
        success : function(result) {
        	updateMemberPhoneResult(result);
        }
	});
}

//获取会员信息
function getMemberInfo(id) {
	$.ajax({
        type : "GET",
        url : headUrl + "getMemberByPrimaryKey",
        cache : false,
        dataType : 'json',
        data:{
        	id : id
        },
        success : function(result) {
        	getMemberInfoResult(result);
        }
	});
}

//是否存在某登录名
function getMemberByLoginName(loginName) {
	$.ajax({
        type : "GET",
        url : headUrl + "getMemberByLoginName",
        cache : false,
        dataType : 'json',
        data:{
        	loginName : loginName
        },
        success : function(result) {
        	getMemberByLoginNameResult(result);
        }
	});
}

//删除收藏
function deleteCol(id) {
	$.ajax({
        type : "GET",
        url : headUrl + "deleteCol",
        cache : false,
        dataType : 'json',
        data:{
        	id : id
        },
        success : function(result) {
        	deleteColResult(result);
        }
	});
}

//添加收藏
function addCollection(objId,type) {
	$.ajax({
        type : "GET",
        url : headUrl + "addCollection",
        cache : false,
        dataType : 'json',
        data:{
        	objId : objId,
			type:type
        },
        success : function(result) {
        	addCollectionResult(result);
        }
	});
}
